﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.ValentineUI {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import Display.DialogUI.*;
    import org.aswing.*;
    import Classes.*;
    import Classes.sim.*;
    import org.aswing.geom.*;
    import Display.*;
    import flash.text.*;
    import org.aswing.border.*;
    import Display.aswingui.*;
    import Modules.stats.types.*;

    public class AdmirersCell extends DataItemCell {

        private const CELL_WIDTH:int = 88;
        private const CELL_HEIGHT:int = 90;

        private var m_admirer:Admirer;
        private var m_cellPanel:JPanel;
        private var m_noPortrait:Boolean = false;
        private var m_noAdmirer:Boolean = false;
        private var m_itemIconHolder:JPanel;
        private var m_itemIconPane:JPanel;
        private var m_itemBgHolder:JPanel;
        private var m_heartBorderSprite:Sprite;
        private var m_cardCounterSprite:Sprite;

        public function AdmirersCell(){
            super(new SoftBoxLayout(SoftBoxLayout.X_AXIS, 0, SoftBoxLayout.LEFT));
        }
        override public function setCellValue(_arg1):void{
            this.m_admirer = (_arg1 as Admirer);
            if (this.m_admirer.name == null){
                this.m_noAdmirer = true;
            };
            if (this.m_admirer.portrait == null){
                this.m_noPortrait = true;
            };
            this.buildCell();
            if (this.m_noPortrait == false){
                m_loader = LoadingManager.load(this.m_admirer.portrait, onIconLoad, LoadingManager.PRIORITY_HIGH);
            };
        }
        protected function buildCell():void{
            this.m_cellPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            this.buildBackground();
            if (this.m_noAdmirer){
                this.buildAddAdmirerCell();
            } else {
                this.buildExistingAdmirerCell();
            };
            this.append(this.m_cellPanel);
            if ((((this.m_noAdmirer == false)) && (ValentineManager.checkUIDForNewCards(this.m_admirer.uid)))){
                this.addHeartBorder();
            };
            if (this.m_noAdmirer == false){
                this.addCardCounter();
            };
            this.addEventListener(MouseEvent.CLICK, this.onMouseClick, false, 0, true);
            ASwingHelper.prepare(this);
        }
        private function addHeartBorder():void{
            this.m_heartBorderSprite = new Sprite();
            var _local1:DisplayObject = (new (ValentineDialog.assetDict["heartBorder"])() as DisplayObject);
            this.m_heartBorderSprite.addChild(_local1);
            this.m_heartBorderSprite.x = (this.m_heartBorderSprite.x + 1);
            this.m_heartBorderSprite.y = (this.m_heartBorderSprite.y + 5);
            this.addChild(this.m_heartBorderSprite);
        }
        private function disableHeartBorder():void{
            this.removeChild(this.m_heartBorderSprite);
        }
        private function addCardCounter():void{
            this.m_cardCounterSprite = new Sprite();
            var _local1:DisplayObject = (new (ValentineDialog.assetDict["counterHeart"])() as DisplayObject);
            this.m_cardCounterSprite.addChild(_local1);
            this.m_cardCounterSprite.x = (this.m_cardCounterSprite.x + 58);
            this.m_cardCounterSprite.y = (this.m_cardCounterSprite.y + 58);
            var _local2:Sprite = new Sprite();
            var _local3:TextField = new TextField();
            var _local4:TextFormat = new TextFormat(EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 12, EmbeddedArt.redTextColor, true);
            _local3.text = this.m_admirer.numCards.toString();
            _local3.border = false;
            _local3.embedFonts = true;
            _local3.setTextFormat(_local4);
            _local2.addChild(_local3);
            var _local5:TextLineMetrics = _local3.getLineMetrics(0);
            _local2.x = (11 - (_local5.width / 2));
            _local2.y = 5;
            this.m_cardCounterSprite.addChild(_local2);
            this.addChild(this.m_cardCounterSprite);
        }
        override protected function initializeCell():void{
            var _local1:JPanel;
            var _local2:AssetPane;
            if (this.m_noPortrait == false){
                _local1 = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.BOTTOM);
                _local2 = new AssetPane(m_itemIcon);
                this.m_itemIconHolder.setBorder(new EmptyBorder(null, new Insets(0, 0, 5, 0)));
                _local1.append(_local2);
                this.m_itemIconPane.append(_local1);
            };
        }
        private function buildBackground():void{
            this.setPreferredSize(new IntDimension(this.CELL_WIDTH, this.CELL_HEIGHT));
            this.setMinimumSize(new IntDimension(this.CELL_WIDTH, this.CELL_HEIGHT));
            this.setMaximumSize(new IntDimension(this.CELL_WIDTH, this.CELL_HEIGHT));
            this.m_cellPanel.setPreferredSize(new IntDimension(this.CELL_WIDTH, this.CELL_HEIGHT));
            this.m_cellPanel.setMinimumSize(new IntDimension(this.CELL_WIDTH, this.CELL_HEIGHT));
            this.m_cellPanel.setMaximumSize(new IntDimension(this.CELL_WIDTH, this.CELL_HEIGHT));
            var _local1:DisplayObject = (new (ValentineDialog.assetDict["noportrait"])() as DisplayObject);
            var _local2:MarginBackground = new MarginBackground(_local1, new Insets(12, 9, 11, 11));
            this.m_cellPanel.setBackgroundDecorator(_local2);
            ASwingHelper.prepare(this.m_cellPanel);
        }
        private function buildAddAdmirerCell():void{
            var _local1:JLabel = new JLabel(ZLoc.t("Dialogs", "ValUI_getadmirer"));
            _local1.setForeground(new ASColor(10056537));
            _local1.setFont(ASwingHelper.getBoldFont(12));
            this.m_cellPanel.append(ASwingHelper.verticalStrut(75));
            this.m_cellPanel.append(_local1);
        }
        private function buildExistingAdmirerCell():void{
            var _local1:JLabel = new JLabel(this.m_admirer.name);
            _local1.setForeground(new ASColor(10056537));
            _local1.setFont(ASwingHelper.getBoldFont(12));
            this.m_itemIconHolder = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            this.m_itemIconPane = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.TOP);
            this.m_itemIconHolder.append(this.m_itemIconPane);
            this.m_itemBgHolder = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.BOTTOM);
            this.m_itemBgHolder.setMinimumSize(new IntDimension(this.m_cellPanel.width, (this.m_cellPanel.height - 15)));
            this.m_itemBgHolder.setPreferredSize(new IntDimension(this.m_cellPanel.width, (this.m_cellPanel.height - 15)));
            this.m_itemBgHolder.setMaximumSize(new IntDimension(this.m_cellPanel.width, (this.m_cellPanel.height - 15)));
            this.m_itemBgHolder.append(this.m_itemIconHolder);
            this.m_cellPanel.append(this.m_itemBgHolder);
            this.m_cellPanel.append(_local1);
        }
        private function onMouseClick(_arg1:MouseEvent):void{
            if (this.m_noAdmirer == true){
                StatsManager.count(StatsCounterType.CARDMAKER, StatsKingdomType.VDAY_2011, StatsPhylumType.ADMIRERS, "person", "blank");
                UI.displayValRewardsMessage(ZLoc.t("Dialogs", "ValUI_getadmirer_popup"), GenericDialogView.TYPE_OK);
            } else {
                StatsManager.count(StatsCounterType.CARDMAKER, StatsKingdomType.VDAY_2011, StatsPhylumType.ADMIRERS, "person", "friend");
                UI.displayValentineCardViewer(this.m_admirer);
                if (this.m_admirer.newCard == true){
                    ValentineManager.markAllAsSeen(this.m_admirer.uid);
                    this.m_admirer.newCard = false;
                };
                if (((this.m_heartBorderSprite) && (this.m_heartBorderSprite.parent))){
                    this.disableHeartBorder();
                };
            };
        }

    }
}//package Display.ValentineUI 
